<template>
  <div>
    <el-form
      size="mini"
      :inline="true"
      ref="label"
      :model="label"
      style="margin: 20px 0"
      class="demo-form-inline"
    >
      <el-form-item label="分类名称" prop="name">
        <el-input v-model="label.name" placeholder="请输入名称"></el-input>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="label.categoryName" placeholder="请选择">
          <el-option label="禁用" value="0"></el-option>
          <el-option label="正常" value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="search">查询</el-button>
        <el-button @click="resetForm('label')">重置</el-button>
        <el-button type="primary">新增</el-button>
      </el-form-item>
    </el-form>

    <el-table :data="labelList" style="width: 100%" border>
      <el-table-column type="index" label="序号" width="55"> </el-table-column>
      <el-table-column prop="name" label="标签名称"> </el-table-column>
      <el-table-column prop="categoryName" label="分类名称"> </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" type="success">编辑</el-button>
          <el-button size="mini" type="danger">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      style="margin-top: 20px; text-align: center"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="label.page"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="label.size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
import { getLabelList } from "../../api/blog";
export default {
  data() {
    return {
      labelList: [],
      label: {
        page: 1,
        size: 10,
        name: "",
        categoryId: "",
      },
      total: 0,
    };
  },
  mounted() {
    this.getLabelList();
  },
  methods: {
    async getLabelList() {
      let res = await getLabelList(this.label);
      this.labelList = res.data.data.records;
      this.total = res.data.data.total;
      console.log(this.labelList);
    },
    handleSizeChange(val) {
      this.label.size = val;
      this.getLabelList();
    },
    handleCurrentChange(val) {
      this.label.page = val;
      this.getLabelList();
    },
    search() {
      this.getLabelList();
      this.$refs["label"].resetFields();
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style scoped >
</style>
